package com.xiaoyu.lanling.router.deeplink;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.xiaoyu.base.app.AppEngine;

import in.srain.cube.util.CLog;

/**
 * A dispatch activity only for external link
 */
public class DeepLinkDispatchActivity extends Activity {

    private static final String TAG = "DeepLinkDispatchActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        finish();

        Uri uri = getIntent().getData();
        if (uri == null) {
            CLog.e(TAG, "uri == null");
            return;
        }

        if (AppEngine.getInstance().hasFinishedInitialJob()) {
            final Context context = this;
            DeepLinkRouter.getInstance().dispatch(context, uri);
        } else {
            final Context context = getApplicationContext();
            AppEngine.getInstance().addFinishInitialJobCallback(() -> {
                DeepLinkRouter.getInstance().dispatch(context, uri);
            });
        }
    }
}